package com.nlp.controller;

import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.nlp.service.SummaryService;

@RestController
@RequestMapping(value = "/controller")
public class NLPController {

	@Autowired
	private SummaryService summary;

	@RequestMapping(value = "/title", method = RequestMethod.POST)
	public String uploadFile(@RequestParam("title")String title) {
		return "title";
	}
	
	@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
	public String uploadFile(@RequestParam("files") MultipartFile[] files
			,@RequestParam("ratio") String ratio) {
		if (null == files || files.length == 0) {
			return null;
		}
//		String secretkid = "24DE884B480D68E2E274277D6BCC619F";
//		String secretkey = "0C09014C043E4BC29399653D25FB6B6E";
		String secretkid = "796B882045E3486CEB98FE412384E5C4";
		String secretkey = "642D23BD297F4E568D814F93E11936E0";
		String language = "en";

		System.out.println(ratio);
		
		try {
			for (MultipartFile multipartFile : files) {
				String summaryInfo = summary.getSummary(
						language, secretkey, secretkid, multipartFile.getInputStream(),
						multipartFile.getOriginalFilename(),ratio);
				return summaryInfo;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "错误";
	}

	@RequestMapping(value = "/htmlSummary", method = RequestMethod.GET)
	public Map<String, Map<String, String>> getHtmlSummary(String uri) {
		if (StringUtils.isBlank(uri)) {
			return null;
		}
//		String secretkid = "24DE884B480D68E2E274277D6BCC619F";
//		String secretkey = "0C09014C043E4BC29399653D25FB6B6E";
		String secretkid = "796B882045E3486CEB98FE412384E5C4";
		String secretkey = "642D23BD297F4E568D814F93E11936E0";
		String language = "en";

		try {
//			Map<String, Map<String, String>>map=Maps.newLinkedHashMap();
//			Map<String, String>map1=Maps.newLinkedHashMap();
//			map1.put("a", "a");
//			map1.put("b", "b");
//			map1.put("c", "c");
//			map1.put("d", "d");
//			Map<String, String>map2=Maps.newLinkedHashMap();
//			map2.put("a", "a");
//			map2.put("b", "b");
//			map2.put("c", "c");
//			map2.put("d", "d");
//			
//			map.put("a1111", map1);
//			map.put("b1111", map2);
//			List<Map<String, String>>list = Lists.newArrayList();
//			list.add(map1);
//			list.add(map2);
//			if(uri==""){
//				return /*list*/summary.getHtmlSummary(language, secretkey, secretkid, uri);
//			}else {
//				return /*list*/summary.getHtmlSummarys(language, secretkey, secretkid, uri);
//			}

			return /*list*/summary.getHtmlSummary(language, secretkey, secretkid, uri);

		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
